import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class FunctionList extends StatelessWidget {
  const FunctionList({super.key});

  @override
  Widget build(BuildContext context) {
    // 功能项列表
    final List<Map<String, dynamic>> functionItems = [
      {'icon': Icons.star, 'title': '我的收藏'},
      {'icon': Icons.history, 'title': '历史浏览'},
      {'icon': Icons.add_shopping_cart, 'title': '上架商品'},
      {'icon': Icons.shopping_cart, 'title': '我购买的'},
      {'icon': Icons.swap_vert, 'title': '我卖出的'},
      {'icon': Icons.comment, 'title': '我的评价'},
      {'icon': Icons.flag, 'title': '举报记录'},
    ];

    return Container(
      padding: EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            '功能',
            style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
          ),
          SizedBox(height: 16),
          ListView.separated(
            padding: EdgeInsets.only(left: 5 ,right: 5),
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemCount: functionItems.length,
            separatorBuilder: (context, index) => Divider(height: 1),
            itemBuilder: (context, index) {
              final item = functionItems[index];
              return ListTile(
                leading: Icon(item['icon'], color: _getIconColor(index)),
                title: Text(item['title']),
                trailing: Icon(Icons.arrow_forward_ios, size: 20),
                onTap: () {
                  switch(index){
                    case 0:
                    // 我的收藏
                    //todo
                      break;
                    case 1:
                    // 历史浏览
                    //todo
                      break;
                    case 2:
                    // 上架商品
                    //todo
                      break;
                    case 3:
                    // 我购买的
                    //todo
                      break;
                    case 4:
                    // 我卖出的
                    //todo
                      break;
                    case 5:
                    // 我的评价
                    //todo
                      break;
                    case 6:
                    // 举报记录
                    //todo
                      break;
                    default:
                      if (kDebugMode) {
                        print('点击了未知功能');
                      }
                  //todo
                  }
                },
              );
            },
          ),
        ],
      ),
    );
  }

  // 根据索引返回不同的图标颜色
  Color _getIconColor(int index) {
    switch (index) {
      case 0:
        return Colors.amber;
      case 1:
        return Colors.purple;
      case 2:
        return Colors.red;
      case 3:
        return Colors.blue;
      case 4:
        return Colors.amber;
      case 5:
        return Colors.grey;
      case 6:
        return Colors.red;
      default:
        return Colors.black;
    }
  }
}